﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ThaireInvestmentWeb.Util;
using ThaireInvestmentWeb.WcfSerivce;

namespace ThaireInvestmentWeb.Models
{
    public class ManageUnitTrustModel
    {
        public SearchUnitTrustFilter SearchFilter { get; set; }
        public ManageUnitTrustModel()
        {
            Init();
        }
        void Init()
        {
            CompanyList = new List<SelectListItem> { WebUtil.SelectListSelectDefault() };
            AssetManagementCompanyList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };
            TypeList = new List<SelectListItem> { WebUtil.SelectListAllDefault() };

            if (SearchFilter == null)
                SearchFilter = new SearchUnitTrustFilter();

            if (_data != null)
            {
                foreach (var item in _data.Companies)
                {
                    CompanyList.Add(new SelectListItem() { Text = item.CompanyNameTh, Value = item.CompanyId.ToString() });
                }
                foreach (var item in _data.AssetManagementCompanies)
                {
                    AssetManagementCompanyList.Add(new SelectListItem() { Text = item.AssetManagementCompanyName, Value = item.AssetManagementCompanyId.ToString() });
                }

                //type
                TypeList.Add(item: new SelectListItem() { Selected = false, Text = "กองทุนระยะยาว", Value = "1" });
                TypeList.Add(item: new SelectListItem() { Selected = false, Text = "กองทุนรวมกลุ่มธุรกิจ", Value = "2" });
            }
        }
        public void ClearFilterAndData()
        {
            Init();
        }

        static UnitTrustHeaderScreenData _data;

        public static ManageUnitTrustModel BuildModel(UnitTrustHeaderScreenData data)
        {
            _data = data;
            return new ManageUnitTrustModel();
        }

        [Required(ErrorMessage = "โปรดระบุ")]
        public int? SelectedCompany
        {
            get { return SearchFilter.Company; }
            set { SearchFilter.Company = value; }
        }
        public IList<SelectListItem> CompanyList { get; set; }
        public int? SelectedType
        {
            get { return SearchFilter.Type; }
            set { SearchFilter.Type = value; }
        }
        public IList<SelectListItem> TypeList { get; set; }

        public int? SelectedAssetManagementCompany
        {
            get { return SearchFilter.AssetManagement; }
            set { SearchFilter.AssetManagement = value; }
        }
        public IList<SelectListItem> AssetManagementCompanyList { get; set; }

        public string Symbol
        {
            get { return SearchFilter.Symbol; }
            set { SearchFilter.Symbol = value; }
        }
        public string FundName
        {
            get { return SearchFilter.FundName; }
            set { SearchFilter.FundName = value; }
        }


        public IList<UnitTrustHeader> Result { get; set; }

        public String SearchBtn { get; set; }
        public String ResetBtn { get; set; }


    }
}